//
//  GuideCollectionCell.m
//  Shengzhuli
//
//  Created by 卡忙科技 on 16/7/19.
//  Copyright © 2016年 kamangkeji. All rights reserved.
//

#import "GuideCollectionCell.h"

@interface GuideCollectionCell()

@property (nonatomic,weak) UIImageView *guideImageView;
@property (nonatomic,weak) UIButton *inBtn;

@end
@implementation GuideCollectionCell

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        UIImageView *guideImageView = [[UIImageView alloc]initWithFrame:self.bounds];
        self.guideImageView = guideImageView;
        [self.contentView addSubview:guideImageView];
        
        UIButton *inBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [inBtn setFrame:CGRectMake((ScreenW-157)/2, ScreenH-65, 157, 35)];
        [inBtn setBackgroundImage:GetImage(@"start.png") forState:UIControlStateNormal];
        [inBtn setBackgroundImage:GetImage(@"start.png") forState:UIControlStateHighlighted];
        [inBtn addTarget:self action:@selector(inAction) forControlEvents:UIControlEventTouchUpInside];
        inBtn.hidden = YES;
        self.inBtn = inBtn;
        //[self.contentView addSubview:inBtn];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handelTap:)];
        
        UIView *view = [[UIView alloc] initWithFrame:(CGRectMake(ScreenW/2-80, ScreenH*3/4, 160, 80))];
        [view addGestureRecognizer:tap];
        view.backgroundColor = [UIColor clearColor];
        self.inView = view;
        self.inView.hidden = YES;
        [self.contentView addSubview:view];
    }
    return self;
}
- (void)handelTap:(UITapGestureRecognizer *)tap {
    [[NSNotificationCenter defaultCenter]postNotificationName:SwitchRooter object:nil];
}
- (void)inAction
{
    [[NSNotificationCenter defaultCenter]postNotificationName:SwitchRooter object:nil];
}
- (void)startAnimation
{
    //已经显示出来的不需要再执行动画
    if (!self.inBtn.hidden) return;
    self.inBtn.hidden = NO;
    self.inBtn.transform = CGAffineTransformMakeScale(0.0, 0.0);
    [UIView animateWithDuration:1.0 delay:0.1 usingSpringWithDamping:0.8 initialSpringVelocity:12 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        self.inBtn.transform = CGAffineTransformIdentity;
    } completion:^(BOOL finished) {
    }];
}
- (void)setIsHiden:(BOOL)isHiden
{
    _isHiden = isHiden;
    self.inBtn.hidden = isHiden;
}
- (void)setImageName:(NSString *)imageName
{
    _imageName = imageName;
    self.guideImageView.image = GetImage(imageName);
}

@end
